# -*- mode: python; -*-

#
# Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
#

import sys

Import('BuildEnv')
AnalyticsEnv = BuildEnv.Clone()
DatabaseEnv = AnalyticsEnv.Clone()

setup_sources = [
           'setup.py',
           'MANIFEST.in',
          ]

setup_sources_rules = []
for file in setup_sources:
    setup_sources_rules.append(DatabaseEnv.Install("", "#/controller/src/analytics/database/" + file))

local_sources = [
           '__init__.py',
]
local_sources_rules = []
for file in local_sources:
    local_sources_rules.append(DatabaseEnv.Install("database", file))

database_pkg = DatabaseEnv.SandeshGenPy('#controller/src/analytics/database/database.sandesh', 'database/sandesh/', False)
cpuinfo_pkg  = DatabaseEnv.SandeshGenPy('#src/contrail-common/base/sandesh/cpuinfo.sandesh', 'database/sandesh/database/', False)
DatabaseEnv.Depends(cpuinfo_pkg, database_pkg)
process_info_pkg = DatabaseEnv.SandeshGenPy('#src/contrail-common/base/sandesh/process_info.sandesh', 'database/sandesh/database/', False)
DatabaseEnv.Depends(process_info_pkg, database_pkg)

sdist_depends = [setup_sources_rules, local_sources_rules, database_pkg, cpuinfo_pkg, process_info_pkg]
sdist_gen = DatabaseEnv.Command('dist', 'setup.py',
                                'cd ' + Dir('.').path + ' && python setup.py sdist')
DatabaseEnv.Depends(sdist_gen, sdist_depends)
DatabaseEnv.Default(sdist_gen)

DatabaseEnv.Alias("database:node_mgr", sdist_gen)
DatabaseEnv.Alias("src/analytics/database:database", sdist_gen)
DatabaseEnv.Alias("contrail-database", sdist_gen)
DatabaseEnv.Alias("nodemgr-full", sdist_gen)

DatabaseEnv['DATABASE_PKG'] = sdist_gen

doc_files = DatabaseEnv.SandeshGenDoc('database.sandesh')
DatabaseEnv.Alias('install', DatabaseEnv.Install(
    DatabaseEnv['INSTALL_MESSAGE_DOC'] + '/contrail-database/',
    doc_files))
DatabaseEnv.SConscript('utils/SConscript', exports='AnalyticsEnv', duplicate = 0)
